﻿using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Traceability_2203.Bais.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class TestController : ControllerBase
    {
        private readonly IMapper mapper;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mapper"></param>
        public TestController(IMapper mapper)
        {
            this.mapper = mapper;
        }

        [HttpGet]
        public void GetValues()
        {
            var people = new People()
            {
                UserId = 1,
                Name = "张三",
                Age = "18",
                BirthDate = new DateTime(2024, 1, 1),
                Weight = 170.10M,
                IsDel = true,
                card = new IDCardDto() { IDCard = "1234567890000" },
                Type = 1,
                List = new List<IDCardDto> { new IDCardDto { IDCard = "111111" }, new IDCardDto { IDCard = "222222" } }
            };
            var person = mapper.Map<Person>(people);

            var abc = "1234T546";
            var aaa = abc.ReplaceString("T", "");

            var List = new List<IDCardDto> { new IDCardDto { IDCard = "111111" }, new IDCardDto { IDCard = "222222" } };
            var list2 = List.Where(x => x.IDCard == "1111").OrderBy(x => x.IDCard);

        }

        //private string ReplaceString(string oldString, string oldValue, string? newValue)
        //{
        //    var result = oldString.Replace(oldValue, newValue);
        //    return result;
        //}

        //扩展方法 静态类 静态方法 this关键字

    }

    public static class StringHelper
    {
        public static string ReplaceString(this string oldString, string oldValue, string? newValue)
        {
            var result = oldString.Replace(oldValue, newValue);
            return result;
        }
    }


    public class People
    {
        public int UserId { get; set; }
        public string Name { get; set; }
        public string Age { get; set; }
        public DateTime BirthDate { get; set; }
        public decimal Weight { get; set; }
        public bool IsDel { get; set; }
        public IDCardDto card { get; set; }
        public int Type { get; set; }
        public List<IDCardDto> List { get; set; }
    }

    public class IDCardDto
    {
        public string IDCard { get; set; }
    }

    public class IDCardDto2
    {
        public string IDCard { get; set; }
    }

    public class Person
    {
        public int UserId { get; set; }
        public string UserName { get; set; }
        public int UserAge { get; set; }
        public string BirthDate { get; set; }
        public int Weight { get; set; }
        public int IsDel { get; set; }
        public string cardIDCard { get; set; }
        public TypeEnum Type { get; set; }
        public List<IDCardDto2> List { get; set; }

    }

    public enum TypeEnum
    {
        管理员 = 1,
        普通用户 = 2
    }

}
